package com.situ.springboot.service.impl;

import com.situ.springboot.mapper.CustomMapper;
import com.situ.springboot.pojo.entity.Custom;
import com.situ.springboot.pojo.entity.User;
import com.situ.springboot.service.CustomService;
import com.situ.springboot.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomServiceImpl implements CustomService {

    @Autowired
    private CustomMapper customMapper;
    @Override
    public Custom login(String name, String password) {
        return customMapper.login(name, password);
    }

    @Override
    public List<Custom> selectall() {
        List<Custom> list = customMapper.selectall();
        return list;
    }

    @Override
    public void add(Custom custom) {
        customMapper.add(custom);
    }

    @Override
    public void deleteById(Integer id) {
        customMapper.deleteById(id);
    }

    @Override
    public Custom selectById(Integer id) {
        return customMapper.selectById(id);
    }

    @Override
    public void update(Custom custom) {
        customMapper.update(custom);
    }

    @Override
    public PageInfo selectByPage(Integer pageNo, Integer pageSize) {

        // limit
        int offset = (pageNo - 1) * pageSize;
        //查找当前页数据
        List<Custom> list = customMapper.selectByPage(offset, pageSize);
        //查找总的数量，目的是为了算总的页数totalPage
        int totalCount = customMapper.selectTotalCount();
        int totalPage = (int)Math.ceil((double) totalCount / pageSize);

        return new PageInfo<Custom>(list, totalPage, pageNo, pageSize);
    }

    @Override
    public void deleteAll(Integer[] ids) {
        customMapper.deleteAll(ids);
    }

    @Override
    public void updateMoney(Custom newCustom) {
        customMapper.updateMoney(newCustom);
    }


}
